package com.yeyks.controller.other;

import com.yeyks.annotation.NeedToken;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.base.Arguments;
import com.yeyks.common.param.StatisticalParam;
import com.yeyks.common.result.StatisticalResult;
import com.yeyks.commonReference.service.order.OrderHeadService;
import com.yeyks.consumer.dal.dao.ShareLogMapper;
import com.yeyks.hotel.dal.dao.HotelInfoMapper;
import com.yeyks.web.AccountUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "统计模块")
@RestController
@Slf4j
@RequestMapping("/stat")
public class NewStatisticalController {

    @Autowired
    HotelInfoMapper hotelInfoMapper;
    @Autowired
    ShareLogMapper shareLogMapper;
    @Autowired
    private OrderHeadService orderHeadService;

    /**
     * 普通统计
     *
     * @return
     */
    @NeedToken
    @ApiOperation(value = "普通统计", notes = "token通过header传入", response = StatisticalResult.class)
    @PostMapping(value = "/statFee")
    public AjaxResponseBody<StatisticalResult> statFee(@Validated StatisticalParam param) {
        StatisticalResult statisticalResult = orderHeadService.statFee(AccountUtils.getLoginUser(), param);
        return AjaxResponseBody.success(statisticalResult);
    }

    /**
     * 统计月和日
     *
     * @return
     */
    @NeedToken
    @ApiOperation(value = "统计月和日", notes = "token通过header传入", response = StatisticalResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "type", value = "类型，(默认1)1月统计，2日统计", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "vipFlag", value = "订单类型逗号隔开，0 c2b，1vip，2b2c，3miniVip", dataType = "string")
    })
    @PostMapping(value = "/monthAndDay")
    public AjaxResponseBody<List<StatisticalResult>> monthAndDay(@RequestParam(name = "type", defaultValue = "1") Integer type,
                                                                 @RequestParam(name = "vipFlag") String vipFlag) {
        Arguments.strIsNull(vipFlag, "订单类型不能为空");
        List<StatisticalResult> statisticalResults = orderHeadService.statMonthAndDay(AccountUtils.getLoginUser(), type, vipFlag);
        return AjaxResponseBody.success(statisticalResults);
    }

}
